<template>
  <el-date-picker
    style="width:100%"
    :editable="false"
    :format="format.format"
    :value-format="format.valueformat"
    placeholder="选择一个或多个日期"
    ref="elDatePicker"
    type="dates"
    v-model="currentValue"
    @input="onInputEvent"
  ></el-date-picker>
</template>
<script>
export default {
  // eslint-disable-next-line vue/require-prop-types
  props: ['label', 'name', 'value', 'format', 'date', 'pickerOptions', 'type', 'range'],
  data() {
    return {
      currentValue: this.value,
      activeValue: []
    }
  },
  watch: {
    value(val) {
      this.currentValue = this.value
    }
  },
  mounted() {
    this.$refs.elDatePicker.showPicker()
    this.$refs.elDatePicker.hidePicker()
  },
  methods: {
    closeTag(a, index) {
      this.activeValue.splice(index, 1)
    },
    chackReturnData(value) {
      if (this.type === 'date') {
        this.$emit('input', this.name, value)
      } else {
        this.$emit('input', this.date[0], value ? value[0] : null)
        this.$emit('input', this.date[1], value ? value[1] : null)
        this.$emit('input', this.name, [value[0], value[1]])
      }
    },
    onInputEvent(value) {
      // console.log(value)
      this.$emit('input', this.name, this.currentValue)
    }
  }
}
</script>
